package com.ffapp.rainmonitorcustom.user;

import android.os.Bundle;
import android.widget.EditText;

import com.ffapp.rainmonitorcustom.R;
import com.ffapp.rainmonitorcustom.basis.BasisActivity;
import com.ffapp.rainmonitorcustom.basis.Constants;
import com.ffapp.rainmonitorcustom.bean.BasisBean;
import com.loopj.android.http.RequestParams;

import butterknife.BindView;
import butterknife.OnClick;
import my.DialogUtils;
import my.http.HttpRestClient;
import my.http.MyHttpListener;

public class ModifyPwdActivity extends BasisActivity {


    @BindView(R.id.edit_new_pwd)
    EditText edit_new_pwd;
    @BindView(R.id.edit_old_pwd)
    EditText edit_old_pwd;
    @BindView(R.id.edit_pwd_confirm)
    EditText edit_pwd_confirm;

    @Override
    public void initViews() {
        super.initViews();
        setContentView(R.layout.user_modify_pwd_activity);

        setTitleLeftButton(null);
        setTitle(R.string.user_modify_password);
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        super.initData(savedInstanceState);

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }


    @OnClick(R.id.btn_ok)
    void post() {
//        String userName = LoginBean.getInstance().getUser().getUserName();
        String pass = edit_old_pwd.getText().toString().trim();
        String passNew = edit_new_pwd.getText().toString().trim();
        String passAgain = edit_pwd_confirm.getText().toString().trim();

        // if (userName.length() == 0) {
        // showToast("请输入用户名");
        // return;
        // }

        if (pass.length() == 0) {
            showToast("请输入旧密码");
            return;
        }

        if (passNew.length() == 0) {
            showToast("请输入新密码");
            return;
        }

        if (passAgain.length() == 0) {
            showToast("请再次输入新密码");
            return;
        }

        if (!passNew.equals(passAgain)) {
            showToast("新密码不一致，请重新输入新密码");
            edit_new_pwd.setText("");
            edit_pwd_confirm.setText("");
            return;
        }

        RequestParams params = new RequestParams();
//        params.put("username", userName);
        params.put("oldPwd", pass);
        params.put("newPwd", passNew);
        showLoading();
        HttpRestClient.post(Constants.URL_USER_MODIFY_PWD, params, new MyHttpListener() {
            @Override
            public void onSuccess(int httpWhat, Object result) {
//                showToast(((BasisBean)result).getStatusInfo());
                DialogUtils.DialogOKmsgFinish(mContext,((BasisBean)result).getStatusInfo());
//                finish();
            }

            @Override
            public void onFinish(int httpWhat) {
                hideLoading();
            }
        }, 0, BasisBean.class);

    }


}
